# @Time : 2020/12/10 13:24
# @Author: sl
# @File : UserJson.py
from flask import request
from app.v2.vo.AddrVo import AddrVo
from app.v2.vo.PersonVo import PersonVo
from framework.api.AbstractApi import AbstractApi
from framework.util.InvertUtil import dict_to_object

'''
 post json串到对象映射 请求示例 http://127.0.0.1:8181/v2/userJson
需要的json串:
{
    "name":"mingzi",
    "addr": {
          "num":5555
      }
 }
'''


class UserJson(AbstractApi):
    # def post(self):
    def handle_post_request(self):
        p1 = PersonVo()
        dict_to_object(request.get_json(), p1)
        print("转成对象", p1.addr.num)
        p1.listData = list()
        addr = AddrVo()
        addr.num = 99999
        p1.listData.append(addr)  # 对象里是list
        return p1
